//
//  StoryboardUtil.m
//  LZCloudApp
//
//  Created by chewyong on 16/1/15.
//  Copyright © 2016年 isoftstone. All rights reserved.
//

#import "StoryboardUtil.h"

@implementation StoryboardUtil

/**
 * 通过名称获取storyboard对象
 * @param stroyboardName storyboard名称，.stroyboard前的字符串
 * @return 返回对应的UIStoryboard对象，如果stroyboardName为空或长度为0，则返回nil
 */
+ (UIStoryboard *)storyboardWithName:(NSString *)stroyboardName {
    if (!stroyboardName || [stroyboardName length] == 0) {
        return nil;
    }
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:stroyboardName bundle:nil];

    return storyboard;
}

/**
 * 通过名称获取storyboard的入口控制器
 * @param stroyboardName storyboard名称，.stroyboard前的字符串
 * @return 返回对应的UIViewController对象，如果stroyboardName为空或长度为0，则返回nil
 */
+ (UIViewController *)storyboardInitialVCWithName:(NSString *)stroyboardName {
    if (!stroyboardName || [stroyboardName length] == 0) {
        return nil;
    }
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:stroyboardName bundle:nil];
    UIViewController *viewController = [storyboard instantiateInitialViewController];

    return viewController;
}

/**
 * 通过stroyboardName和storyboardId获取指定的控制器
 * @param stroyboardName storyboard名称，.stroyboard前的字符串
 * @param storyboardId storyboard标示，用于获取storyboard中的控制器
 * @return 返回对应的UIViewController对象，如果stroyboardName或storyboardId为空或长度为0，则返回nil
 */
+ (UIViewController *)storyboardVCWithName:(NSString *)stroyboardName identifier:(NSString *)storyboardId {
    if (!stroyboardName || [stroyboardName length] == 0 || !storyboardId || [storyboardId length] == 0) {
        return nil;
    }
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:stroyboardName bundle:nil];
    UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:storyboardId];

    return viewController;
}

@end
